<?php
$customerServices = new CustomerServices();
$orderServices = new OrdersService();
if(isset($_GET['opt']))
{
	$opt = $_GET['opt'];
	$moduleID = $moduleService->getModuleIDByFuncAndOpt($context, $result, $func, $opt);
	$permit = $permitService->checkPermition($context, $result, $_SESSION['user']['type'], $moduleID);
	if($opt == "add" && $permit ==true)
	{
		$countryList = $countryService->findAllCountry($context, $result);
		$smarty->assign('countryList', $countryList);
		$bankList = $bankService->findAllBank($context, $result);
		$smarty->assign('bankList', $bankList);
		$smarty->display($templateDir . "/temp1/addCustomer.tpl");
	}
	if($opt == "edit" && $permit ==true)
	{
		if(isset($_GET['id']) && is_numeric($_GET['id']))
		{
			$countryList = $countryService->findAllCountry($context, $result);
			$smarty->assign('countryList', $countryList);
			$customerUser = $customerServices->getCustomerByOid($context, $result, $_GET['id']);
			$bankList = $bankService->findAllBank($context, $result);
			$smarty->assign('bankList', $bankList);
			$smarty->assign('customerUser', $customerUser);
			if($customerUser->getBankAccountDomain1() != null)
			{
				$smarty->assign('bankAccountDomain1', $customerUser->getBankAccountDomain1());
			}
			
			if($customerUser->getBankAccountDomain2() != null)
			{
				$smarty->assign('bankAccountDomain2', $customerUser->getBankAccountDomain2());
			} 
			
			$smarty->display($templateDir . "/temp1/editCustomer.tpl");
		}
	}
	if($opt == "list" && $permit ==true)
	{
		$start=$p->findStart($configPage['limit']);
		$count=$customerServices->countAllCustomer($context, $result);
		$pages=$p->findPages($count,$configPage['limit']);
		$page_list = $p->pagesList($_GET['page'],$pages,$configPage);
		$customerList = $customerServices->getAllCustomerByRange($context, $result, $start, $configPage['limit']);
		$total = "Page ".$_GET['page']." in ".$pages. " Pages";
		$smarty->assign('total', $total);
		$smarty->assign('page_list', $page_list);
		$smarty->assign('customerList', $customerList);
		$smarty->display($templateDir . "/temp1/listCustomer.tpl");
	}
	if($opt == "changePassC")
	{
		$smarty->display($templateDir . "/temp1/changePass.tpl");
			
	}
	if($opt == "cusLedger" && $permit ==true)
	{
		$start=$p->findStart($configPage['limit']);
		$paymentServices = new PaymentServices();
		$count=$paymentServices->countAllCustomerID($context, $result);
		$pages=$p->findPages($count,$configPage['limit']);
		$page_list = $p->pagesList($_GET['page'],$pages,$configPage);
			
		$ledgerService = new LedgerService();
		$ledgerSummaryArr = $ledgerService->getAllSummaryPaymentOfCustomerByRange($context, $result, $start, $configPage['limit']);
		$total = "Page ".$_GET['page']." in ".$pages. " Pages";
		$smarty->assign('total', $total);
		$smarty->assign('page_list', $page_list);
		$smarty->assign("ledgerSummaryArr", $ledgerSummaryArr);
		$smarty->display($templateDir . "/temp1/listCusLedger.tpl");
	}
	if($opt == "viewLedger" && $permit ==true)
	{
		if(isset($_GET['cusID']))
		{
			$paymentServices = new PaymentServices();
			$cusID = $_GET['cusID'];
			$start=$p->findStart($configPage['limit']);
			$count=$paymentServices->countAllByCusID($context, $result, $cusID);
			$pages=$p->findPages($count,$configPage['limit']);
			$page_list = $p->pagesList($_GET['page'],$pages,$configPage);
			$total = "Page ".$_GET['page']." in ".$pages. " Pages";

			$ledgerService = new LedgerService();
			$ledgerDetailArr = $ledgerService->getAllLedgerDetailByCusID($context, $result, $start, $configPage['limit'], $cusID);
			//print_r($ledgerDetailArr);

		}
			
		$smarty->assign('total', $total);
		$smarty->assign('page_list', $page_list);
		$smarty->assign('ledgerDetailArr', $ledgerDetailArr);
		$smarty->display($templateDir . "/temp1/viewCusLedger.tpl");
	}
	
	if($opt == 'viewLedgerDetailC' && $permit ==true)
	{
		$order = $orderServices->getOrderByOid($context, $result, $_GET['id']);
		 
		$type = $order->getOrdersDomain()->getType();
		if($type >= 4)
		{
			$orderDetailArr = $order->getOrderDetail();
			if(!Tool::isEmpty($orderDetailArr))
			{
				$smarty->assign('strCurency', $orderDetailArr[0]->getOrderdetailsDomain()->getCurrency());
			}
			$smarty->assign('order', $order);
		}
		 
		$smarty->display($templateDir . "/temp1/viewOrderPI.tpl");
	}
}
?>